//
//  ContentView.swift
//  XFRequestDemo
//
//  Created by 雪飞 on 2021/10/26.
//

import SwiftUI
import XFRequest
import KakaJSON
let XF = XFRequest.default("http://v.juhe.cn/toutiao/index",rmsg: RMSG(codeKey: "error_code", code: 0, msgKey: "reason", dataKey: "result"))
/// 聚合数据
let key:String = "09fb2aabb19daa4fcd7bfb2ffea06271"


struct ContentView: View {
    @State var titles:[ListModel] = [ListModel(title: "默认", type: .Default),
                                     ListModel(title: "对结果进行拦截处理,只取需要的", type: .Needed),
                                     ListModel(title: "拦截处理并返回模型", type: .Model)]
    @State var type: newstype = .Default
    var body: some View {
        NavigationView {
            List{
                ForEach(titles){model in
                    NavigationLink {
                        News(type: model.type)
                    } label: {
                        Text(model.title)
                    }
                }
            }
            .navigationTitle("XFRequest Demo")
        }
    }
}

struct ListModel:Identifiable{
    let id = UUID().uuidString
    var title:String
    var type:newstype
}

enum newstype:Int {
    /// 默认
    case Default = 0
    /// 返回需要的数据
    case Needed
    /// 返回模型
    case Model
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
